package kos.robert.screens;

import java.awt.*;

import javax.swing.JFrame;

public class Screen {
	private GraphicsDevice vc;

	public Screen() {
		GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
		vc = env.getDefaultScreenDevice();
	}

	public void setFullScreen(DisplayMode dm, JFrame window) {
		window.setUndecorated(true);
		window.setResizable(false);
		vc.setFullScreenWindow(window);

		if (dm != null && vc.isDisplayChangeSupported()) {
			vc.setDisplayMode(dm);
		}
	}

	public Window getFullScreenWindow() {
		return vc.getFullScreenWindow();
	}

	public void restoreScreen() {
		Window w = vc.getFullScreenWindow();
		if (w != null) {
			w.dispose();
		}
		vc.setFullScreenWindow(null);
	}

	public static String displayModeToString(DisplayMode dm) {
		StringBuffer sb = new StringBuffer();
		sb.append("Resolution: ");
		sb.append(dm.getWidth());
		sb.append("x");
		sb.append(dm.getHeight());
		sb.append(", Bits: ");
		sb.append(dm.getBitDepth());
		sb.append(", Refresh rate: ");
		sb.append(dm.getRefreshRate());
		sb.append("Hz");
		return sb.toString();
	}

	public static String displayModeToString(DisplayMode[] dm) {
		StringBuffer sb = new StringBuffer();
		for (DisplayMode displayMode : dm) {
			sb.append(displayModeToString(displayMode));
			if (displayMode != dm[dm.length - 1])
				sb.append("\n");
		}
		return sb.toString();
	}
}
